package com.alex.cms.web.controllers;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.alex.cms.domain.CmsArticle;
import com.alex.cms.domain.CmsCategory;
import com.alex.cms.domain.CmsUser;
import com.alex.cms.domain.CmsVote;
import com.alex.cms.service.ICmsArticleService;
import com.alex.cms.service.ICmsCategoryService;
import com.alex.cms.service.ICmsChannelService;
import com.alex.cms.service.ICmsCommentService;
import com.alex.cms.service.ICmsVoteService;
import com.alex.cms.web.constants.CMSConstants;
import com.alex.cms.web.enums.ArticleType;
import com.alex.cms.web.form.ArticleForm;
import com.alex.cms.web.vo.ArticleVo;
import com.alex.cms.web.vo.CommentVo;
import com.alex.cms.web.vo.OptionVo;
import com.alex.cms.web.vo.ResultVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bawei.common.Exception.CMSSystemException;
import com.bawei.common.utils.AssertionUtil;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * <p>
 * 文章内容表 前端控制器
 * </p>
 *
 * @author alex
 * @since 2019-09-11
 */
@Controller
@RequestMapping("/article")
public class CmsArticleController {

	@Autowired
	private ICmsArticleService articleService;

	@Autowired
	private ICmsCategoryService categoryService;

	@Autowired
	private ICmsChannelService channelService;
	@Autowired
	private ICmsVoteService voteService;

	@Autowired
	private ICmsCommentService commentService;

	/**
	 * 
	 * @Title: showArticle
	 * @Description: 文章发布的展示页面接口
	 * @return
	 * @return ModelAndView
	 */
	@RequestMapping("/edit")
	public ModelAndView showArticle() {
		// 指定跳转的jsp页面
		ModelAndView mav = new ModelAndView("/user-space/blog_edit");
		// 页面需要的分类信息
		List<CmsCategory> categories = categoryService.list();
		ArticleForm articleForm = new ArticleForm();
		// CMSConstants.CATEGORIES：页面指定的别称，需要在CmsConstants中定义
		mav.addObject(CMSConstants.CATEGORIES, categories);
		mav.addObject("blog", articleForm);
		return mav;
	}

	/**
	 * 
	 * @Title: editArticle
	 * @Description:发布文章，功能有上传文件，一般上传到fastFDS文件服务器
	 * @param articleForm
	 *            页面需要的文章信息
	 * @param id
	 *            前端传过来的id值
	 * @param file
	 *            上传的文件
	 * @return
	 * @return ModelAndView 我的文章页面
	 */
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	public ModelAndView editArticle(ArticleForm articleForm, MultipartFile file, HttpSession session, @RequestParam(required = false, name = "isDelCover") Integer isDelCover) {
		// 获取登录时保存到session的用户信息
		CmsUser user = (CmsUser) session.getAttribute(CMSConstants.LOGIN_USER);
		// 指定文章发布成功跳转到哪个页面（/article/list?userid=xxxx这是文章列表的url
		ModelAndView mav = new ModelAndView("redirect:/article/list?userid=" + user.getId());
		CmsArticle article = new CmsArticle();
		String fileName = "";
		/********* 文章修改的功能 *********/
		if (file.isEmpty()) {
			// 判断前端的cover参数是否有值
			if (articleForm.getCover() != null) {
				// isDelCover：是否删除，1为删除图片
				if (isDelCover == 1) {
					// 构造要被删除的封面图片文件对象
					File deleteFile = new File(session.getServletContext().getRealPath("/") + articleForm.getCover());
					// java.io.File的判断方法，判断文件是否存在
					if (deleteFile.exists()) {
						// java.io.File的删除方法
						deleteFile.delete();
					}
				}
			}
			/******** 文章修改的功能 **********/
		} else {
			// 图片上传的功能
			// 获取图片文件的原始文件名
			String name = file.getOriginalFilename();
			// 获取文件的后缀名，比如：.jpg .txt....
			String suffix = name.substring(name.lastIndexOf("."));
			// 上传后的文件名，随机生成一个唯一的UUID
			fileName = UUID.randomUUID().toString() + suffix;
			// 文件保存路径，一般实际开发中的fastfds文件服务器指定路径
			File file2 = new File(session.getServletContext().getRealPath("/") + CMSConstants.FILE_SAVE_PATH);
			// 判断文件路径是否存在，不存在重新创建
			if (!file2.exists()) {
				// java.io.File的创建文件路径
				file2.mkdir();
				// java.io.File的设置权限的方法，读写权限
				// file2.canExecute();
				// file2.canRead();
				// file2.canWrite();
			}
			File picFile = new File(session.getServletContext().getRealPath("/") + CMSConstants.FILE_SAVE_PATH + fileName);
			// spring的上传功能
			try {
				file.transferTo(picFile);
			} catch (Exception e1) {
				mav.addObject("message", "文章上传失败！");
				mav.addObject("blog", articleForm);
				mav.setViewName("user-space/blog_edit");
			}
		}
		// 文章编辑功能
		if (!file.isEmpty()) {
			// 如果没有提交封面图片，则设置该字段为null
			article.setPicture(CMSConstants.FILE_SAVE_PATH + fileName);
		} else {
			if (articleForm.getCover() != null) {
				if (isDelCover == 1) {
					// 如果设置实体属性值为null，mybatis-plus将不会修改相应的字段
					article.setPicture("");
				} else {
					// 如果原来有封面，则使用原来的图片
					article.setPicture(articleForm.getCover());
				}
			} else {
				// 如果原来封面，则设置为null
				article.setPicture("");
			}
		}
	
		// 保存文章
		if (articleForm.getId() != null) {
			article.setId(articleForm.getId());
		}
		article.setTitle(articleForm.getTitle());
		article.setSummary(articleForm.getSummary());
		article.setContent(articleForm.getContent());
		article.setKeywords(articleForm.getKeywords());
		article.setOriginal(articleForm.getOriginal());
		article.setCategroyId(articleForm.getCategory().getId());
		// 获取频道ID
		Integer channelId = categoryService.getById(articleForm.getCategory().getId()).getChannelId();
		article.setChannelId(channelId);
		article.setUserId(user.getId());
		article.setHot(false);
		article.setCreated(new Date());
		article.setUpdated(article.getCreated());
		// 文章编辑后状态设置为0，然后进行审核
		article.setStatus(0);
		article.setType(ArticleType.HTML.ordinal());
		articleService.saveOrUpdate(article);
		return mav;
	}

	/**
	 * 
	 * @Title: getArticleList
	 * @Description: 文章列表
	 * @param userId
	 * @return
	 * @return ModelAndView
	 */
	@RequestMapping("/list")
	public ModelAndView getArticleList(@RequestParam("userid") Integer userId) {
		// 指定文章列表的jsp
		ModelAndView mav = new ModelAndView("/user-space/blog_list");
		// 根据用户ID获取本用户的所有文章
		QueryWrapper<ArticleVo> queryWrapper = new QueryWrapper<ArticleVo>();
		queryWrapper = queryWrapper.eq("user_id", userId).ne("status", 0);
		// 手动创建sql，返回一个articleVo的集合
		List<ArticleVo> articles = articleService.selectAllArticlesByUserId(queryWrapper);
		mav.addObject("blogs", articles);
		return mav;
	}

	/**
	 * 
	 * @Title: showArticleEdit
	 * @Description: 我的文章列表的编辑功能（
	 * @param articleId
	 * @return
	 * @return ModelAndView
	 */
	@Deprecated
	@RequestMapping("/editArticle/{articleId}")
	public ModelAndView showArticleEdit(@PathVariable("articleId") Integer articleId) {
		CmsArticle article = articleService.getById(articleId);
		ModelAndView mav = null;
		if (article.getType() == 0) {
			mav = new ModelAndView("redirect:/article/edit/id/" + articleId);
		} else {
			mav = new ModelAndView("redirect:/article/vote/edit/");
			mav.addObject("id", article);
		}
		return mav;
	}

	/**
	 * 
	 * @Title: showArticleEditView
	 * @Description: 文章编辑
	 * @param articleId
	 * @return
	 * @return ModelAndView
	 */
	@RequestMapping("/edit/id/{articleId}")
	public ModelAndView showArticleEditView(@PathVariable("articleId") Integer articleId) {
		// 指定跳转到哪个jsp，"user-space/blog_edit"是jsp的路径
		ModelAndView mav = new ModelAndView("user-space/blog_edit");

		ArticleForm articleForm = new ArticleForm();
		// 获取所有的分类
		List<CmsCategory> categories = categoryService.list();
		// 返回到页面的数据
		mav.addObject(CMSConstants.CATEGORIES, categories);

		try {
			// 根据文章ID获取文章
			CmsArticle article = articleService.getById(articleId);

			// 断言要抛出异常，断言之后执行的语句都是正确流程
			AssertionUtil.assertFalse(article == null, CMSConstants.ARTICLE_IS_NOT_EXIST);

			articleForm.setId(articleId);
			articleForm.setTitle(article.getTitle());
			articleForm.setSummary(article.getSummary());
			articleForm.setContent(article.getContent());

			// 设置文章封面图片的值
			articleForm.setCover(article.getPicture());

			CmsCategory category = new CmsCategory();
			category.setId(article.getCategroyId());

			articleForm.setCategory(category);
			// 返回页面数据，"blog"是前端定义的名字
			mav.addObject("blog", articleForm);
		} catch (CMSSystemException e) {
			// 视图仍然定位到文章编辑页面，错误消息在编辑页面显示
			mav.addObject("message", e.getMessage());
		}

		return mav;
	}

	/**
	 * 
	 * @Title: removeArticleById
	 * @Description: 删除文章
	 * @param articleId
	 * @return
	 * @return ReusltVo
	 */
	@RequestMapping("/remove")
	@ResponseBody
	public ResultVo removeArticleById(@RequestParam("id") Integer articleId) {
		// ajax定义的返回数据结构，所以定义这个对象的时候看ajax的data结构是什么
		ResultVo result = new ResultVo();
		// 根据文章ID删除，返回结果
		boolean removeResult = articleService.removeById(articleId);
		// 返回结果都统一放在constants中，便于维护
		result.setStatus(removeResult ? CMSConstants.RESULT_STATUS_SUCCESS : CMSConstants.RESULT_STATUS_ERROR);
		result.setMessage(removeResult ? CMSConstants.RESULT_DELETE_MESSAGE_SUCCESS : CMSConstants.RESULT_DELETE_MESSAGE_ERROR);

		return result;
	}

	/**
	 * 
	 * @Title: showArticleDetail
	 * @Description: 文章详情
	 * @param articleId
	 * @return
	 * @return ModelAndView
	 */
	@RequestMapping("/{articleId}")
	public ModelAndView showArticleDetail(@PathVariable("articleId") Integer articleId) {
		ModelAndView mav = new ModelAndView("blog");
		// 根据文章ID获取所有文章列表
		List<ArticleVo> blogs = articleService.selectAllArticlesByUserId(new QueryWrapper<ArticleVo>().eq("cms_article.id", articleId));

		ArticleVo blog = blogs.get(0);
		// 文章点击量+1
		blog.setHits(blog.getHits() + 1);
		// 保存文章
		CmsArticle entity = new CmsArticle();
		entity.setId(blog.getId());
		entity.setHits(blog.getHits());
		articleService.saveOrUpdate(entity);
		mav.addObject("blog", blog);
		List<CmsArticle> hotBlogs = articleService.list(new QueryWrapper<CmsArticle>().eq("hot", 1).eq("type", 0));
		mav.addObject("hitBlogs", hotBlogs);
		// 点击率排行榜
		List<CmsArticle> hitsBlogs = articleService.selectAllArticlesByHits(new Page<CmsArticle>(1, 10), new QueryWrapper<CmsArticle>().orderByDesc("hits"));
		mav.addObject("articleHits", hitsBlogs);
		// 评论排行榜
		List<CmsArticle> commentsBlogs = articleService.selectAllArticlesByHits(new Page<CmsArticle>(1, 10), new QueryWrapper<CmsArticle>().orderByDesc("comments"));
		mav.addObject("articleComments", commentsBlogs);
		Page<CommentVo> page = new Page<CommentVo>(1, 10);
		// 评论分页列表
		IPage<CommentVo> comments = commentService.selectAllCommentsByPage(page, new QueryWrapper<CommentVo>().eq("cms_article.id", articleId).orderByDesc("cms_comment.created"));
		mav.addObject("comments", comments.getRecords());
		mav.addObject("currentPage", comments.getCurrent());
		mav.addObject("pages", comments.getPages());
		return mav;
	}

	@RequestMapping("/nextArticle")
	public ModelAndView getNextArticle(@RequestParam("articleId") Integer articleId, @RequestParam("type") Integer type) {
		CmsArticle article = articleService.getById(articleId);
		List<CmsArticle> list = articleService.list(new QueryWrapper<CmsArticle>().eq("channel_id", article.getChannelId()).orderByDesc("created"));
		ModelAndView mav = null;
		if (CollectionUtils.isEmpty(list)) {
			mav = new ModelAndView("redirect:/article/" + articleId);
			return mav;
		}
		if (list.size() == 1) {
			mav = new ModelAndView("redirect:/article/" + articleId);
			return mav;
		}
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getId().intValue() == articleId.intValue()) {
				if (type == 1) {
					if (i < list.size() - 1) {
						mav = new ModelAndView("redirect:/article/" + list.get(i + 1).getId());
						return mav;
					} else if (i == list.size() - 1) {
						mav = new ModelAndView("redirect:/article/" + list.get(list.size() - 1).getId());
						return mav;
					}
				} else {
					if (i == 0) {
						mav = new ModelAndView("redirect:/article/" + list.get(0).getId());
						return mav;
					} else if (i <= list.size() - 1) {
						mav = new ModelAndView("redirect:/article/" + list.get(i - 1).getId());
						return mav;
					}
				}
			}
		}
		return mav;
	}

	/**
	 * 
	 * @Title: showArticleDetail
	 * @Description: 文章详情
	 * @param articleId
	 * @return
	 * @return ModelAndView
	 */
	@RequestMapping("/commentDetail")
	public ModelAndView showArticleDetail(@RequestParam("articleId") Integer articleId, @RequestParam("pageNo") Integer pageNo) {
		ModelAndView mav = new ModelAndView("blog");
		// 根据文章ID获取所有文章列表
		List<ArticleVo> blogs = articleService.selectAllArticlesByUserId(new QueryWrapper<ArticleVo>().eq("cms_article.id", articleId));

		ArticleVo blog = blogs.get(0);
		// 文章点击量+1
		blog.setHits(blog.getHits() + 1);
		// 保存文章
		CmsArticle entity = new CmsArticle();
		entity.setId(blog.getId());
		entity.setHits(blog.getHits());
		articleService.saveOrUpdate(entity);
		mav.addObject("blog", blog);
		List<CmsArticle> hotBlogs = articleService.list(new QueryWrapper<CmsArticle>().eq("hot", 1).eq("type", 0));
		mav.addObject("hitBlogs", hotBlogs);
		// 点击率排行榜
		List<CmsArticle> hitsBlogs = articleService.selectAllArticlesByHits(new Page<CmsArticle>(1, 10), new QueryWrapper<CmsArticle>().orderByDesc("hits"));
		mav.addObject("articleHits", hitsBlogs);
		// 评论排行榜
		List<CmsArticle> commentsBlogs = articleService.selectAllArticlesByHits(new Page<CmsArticle>(1, 10), new QueryWrapper<CmsArticle>().orderByDesc("comments"));
		mav.addObject("articleComments", commentsBlogs);
		pageNo = pageNo != null ? pageNo : 1;
		Page<CommentVo> page = new Page<CommentVo>(pageNo, 10);
		IPage<CommentVo> comments = commentService.selectAllCommentsByPage(page, new QueryWrapper<CommentVo>().eq("cms_article.id", articleId).orderByDesc("cms_comment.created"));
		mav.addObject("comments", comments.getRecords());
		mav.addObject("currentPage", comments.getCurrent());
		mav.addObject("pages", comments.getPages());
		return mav;
	}

	/**
	 * 
	 * @Title: showVoteArticle
	 * @Description: 跳转到发布投票的页面
	 * @return
	 * @return ModelAndView
	 */
	@RequestMapping("/vote/edit")
	public ModelAndView showVoteArticle(HttpSession session) {
		ModelAndView mav = new ModelAndView("/user-space/vote_edit");
		CmsUser user = (CmsUser) session.getAttribute(CMSConstants.LOGIN_USER);
		if(user == null){
			mav.setViewName("redirect:/user/login");
			return mav;
		}
		return mav;
	}

	/**
	 * 
	 * @Title: editVoteArticle
	 * @Description: 发布投票的操作，保存投票文章
	 * @param voteId
	 * @param title
	 * @param options
	 * @param session
	 * @return
	 * @return ModelAndView
	 */
	@RequestMapping(value = "/vote/edit", method = RequestMethod.POST)
	public ModelAndView editVoteArticle(@RequestParam(value = "id", required = false) Integer voteId, @RequestParam(value = "title", required = false) String title, @RequestParam("options") List<String> options, HttpSession session) {
		// session中获取用户信息
		CmsUser user = (CmsUser) session.getAttribute(CMSConstants.LOGIN_USER);
		ModelAndView mav = new ModelAndView("redirect:/article/list?userid=" + user.getId());
		// 基于考纲要求，定义一个LinkedHashMap
		Map<String, String> map = new LinkedHashMap<>();
		if (!CollectionUtils.isEmpty(options)) {
			// 定义一个大写字母A
			char uc = 'A';
			for (int i = 0; i < options.size(); i++) {
				// (char) (uc + i)这是对char计算，转换成String字符串
				map.put((char) (uc + i) + "", options.get(i));
			}
		}
		CmsArticle article = new CmsArticle();
		String content = "";
		try {
			// map转json
			content = (new ObjectMapper()).writeValueAsString(map);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		if (voteId != null) {
			article.setId(voteId);
		}
		article.setTitle(title);
		article.setContent(content);
		article.setUserId(user.getId());
		article.setCategroyId(0);
		article.setChannelId(0);
		article.setCreated(new Date());
		article.setHot(false);
		article.setUpdated(article.getCreated());
		// 获取ArticleType枚举类的值，0,1,2...
		article.setType(ArticleType.VOTE.ordinal());
		articleService.save(article);
		return mav;
	}

	/**
	 * 
	 * @Title: showVoteArticleDetail
	 * @Description: 投票页面详情，需要判断是否投过票
	 * @param articleId
	 * @param session
	 * @return
	 * @return ModelAndView
	 */
	@RequestMapping("/vote/{articleId}")
	public ModelAndView showVoteArticleDetail(@PathVariable("articleId") Integer articleId, HttpSession session) {
		// 从session获取用户信息
		CmsUser user = (CmsUser) session.getAttribute(CMSConstants.LOGIN_USER);
		// 根据文章id和用户id查找投票结果表
		List<CmsVote> list = voteService.list(new QueryWrapper<CmsVote>().eq("article_id", articleId).eq("user_id", user.getId()));
		ModelAndView mav = null;
		// 判断是否有数据
		if (CollectionUtils.isEmpty(list)) {
			// 没投票的页面
			mav = new ModelAndView("/user-space/vote_do");
			// 根据文章ID获取所有文章列表
			List<ArticleVo> blogs = articleService.selectAllArticlesByUserId(new QueryWrapper<ArticleVo>().eq("cms_article.id", articleId));
			ArticleVo blog = blogs.get(0);
			// 文章点击量+1
			blog.setHits(blog.getHits() + 1);
			// 保存文章
			CmsArticle entity = new CmsArticle();
			entity.setId(blog.getId());
			entity.setHits(blog.getHits());
			entity.setUserId(user.getId());
			articleService.saveOrUpdate(entity);
			mav.addObject("vote", blog);
			List<CmsArticle> hotBlogs = articleService.list(new QueryWrapper<CmsArticle>().eq("hot", 1).eq("type", 1));
			mav.addObject("hitvotes", hotBlogs);
			try {
				// json转map
				mav.addObject("options", new ObjectMapper().readValue(blog.getContent(), Map.class));
			} catch (JsonParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JsonMappingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			// 投过票的，跳转到结果页面
			mav = new ModelAndView("/user-space/vote_result");
			// 根据文章id获取所有文章相关的信息
			List<ArticleVo> blogs = articleService.selectAllArticlesByUserId(new QueryWrapper<ArticleVo>().eq("cms_article.id", articleId));
			ArticleVo blog = blogs.get(0);
			Map<String, String> map = null;
			try {
				// json转map
				map = new ObjectMapper().readValue(blog.getContent(), Map.class);
			} catch (JsonParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JsonMappingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			// 定义一个存放投票选项的集合
			List<OptionVo> options = new ArrayList<OptionVo>();
			// 遍历map，获取key,value
			for (Map.Entry<String, String> entry : map.entrySet()) {
				// 定义一个选项VO对象
				OptionVo option = new OptionVo();
				// set文章标题
				option.setTitle(entry.getValue());
				// 根据文章ID统计投票文章的投票数，临时存储到投票选项的VO对象中
				int currentNum = voteService.count(new QueryWrapper<CmsVote>().eq("article_id", articleId).eq("option1", entry.getKey()));
				option.setVoteNum(currentNum);
				options.add(option);
			}
			// 根据文章ID统计投票文章的总投票数
			int totalNum = voteService.count(new QueryWrapper<CmsVote>().eq("article_id", articleId));
			// 主要用于bootstrap进度条所需要的数据
			// 投票选项
			mav.addObject("options", options);
			// 总投票数
			mav.addObject("totalNum", totalNum);
			// 文章信息
			mav.addObject("vote", blog);
			List<CmsArticle> hotBlogs = articleService.list(new QueryWrapper<CmsArticle>().eq("hot", 1).eq("type", 1));
			mav.addObject("hitvotes", hotBlogs);
		}

		return mav;
	}

	/**
	 * 
	 * @Title: doVote
	 * @Description: 投票
	 * @param id
	 * @param option
	 * @param request
	 * @return
	 * @return ModelAndView
	 */
	@RequestMapping(value = "/vote/dovote", method = RequestMethod.POST)
	public ModelAndView doVote(Integer id, String option, HttpServletRequest request) {

		ModelAndView mav = new ModelAndView("redirect:/article/vote/" + id);

		HttpSession session = request.getSession(false);
		// 判断用户是否登录，未登录不能投票
		if (session.getAttribute(CMSConstants.LOGIN_USER) == null) {
			mav.setViewName("redirect:/user/login");
			return mav;
		}
		// session中获取用户信息
		CmsUser user = (CmsUser) session.getAttribute(CMSConstants.LOGIN_USER);
		// 保存投票结果表
		CmsVote vote = new CmsVote();
		vote.setArticleId(id);
		vote.setUserId(user.getId());
		vote.setOption1(option);
		voteService.save(vote);
		return mav;
	}

	/**
	 * 
	 * @Title: getArticleList
	 * @Description: 文章列表
	 * @param userId
	 * @return
	 * @return ModelAndView
	 */
	@RequestMapping("/auditList")
	public ModelAndView getArticleAuditList() {
		// 指定文章列表的jsp
		ModelAndView mav = new ModelAndView("redirect:/article/list");
		// 根据用户ID获取本用户的所有文章
		QueryWrapper<ArticleVo> queryWrapper = new QueryWrapper<ArticleVo>();
		queryWrapper = queryWrapper.eq("status", -1);
		// 手动创建sql，返回一个articleVo的集合
		List<ArticleVo> articles = articleService.selectAllArticlesByUserId(queryWrapper);
		mav.addObject("blogs", articles);
		return mav;
	}
	
	@RequestMapping("/setHot")
	@ResponseBody
	public ResultVo setHotByArticleId(@RequestParam("id")Integer id){
		ResultVo resultVo = new ResultVo();
		CmsArticle article = articleService.getById(id);
		boolean ret = false;
		if(article != null){
			if (article.getHits()>=CMSConstants.ARTICLE_HOT_VALUE) {
				article.setHot(true);
				ret = articleService.updateById(article);
			}
		}
		resultVo.setStatus(ret ==true ? CMSConstants.RESULT_STATUS_SUCCESS:CMSConstants.RESULT_STATUS_ERROR);
		resultVo.setMessage(ret == true? CMSConstants.ARTICLE_SET_HOT_SUCCESS:CMSConstants.ARTICLE_SET_HOT_ERROR);
		return resultVo;
	}

}
